package com.jing.tanksnack.config;

import com.jing.tanksnack.entity.TankClient;
import com.jing.tanksnack.entity.TankServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import java.net.UnknownHostException;

@Configuration
public class ServerConfig  {

    public static String serverIp;
    public static int serverTcpPort;
    public static int serverUdpPort;
    public static int id;
    public static int startUdp;
    public static int cs;//客户端还是服务器启动
    @Autowired
    private Environment env;

    @Bean
    public void init() throws UnknownHostException {
        serverIp=env.getProperty("server.ip");
        serverTcpPort=Integer.parseInt(env.getProperty("server.tcp.port"));
        serverUdpPort=Integer.parseInt(env.getProperty("server.udp.port"));
        id=Integer.parseInt(env.getProperty("start.id"));
        startUdp=Integer.parseInt(env.getProperty("start.udp.port"));
        cs=Integer.parseInt(env.getProperty("cs"));
        if(ServerConfig.cs==0){
            new TankServer().start();
        }
        if(ServerConfig.cs==1){
            TankClient tc = new TankClient();
            tc.launchFrame();
        }
    }
}
